<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$("#dialog_update_budget_time").dialog({autoOpen:false, modal:true, width:500, height:300});
	$(".detail").colorbox({width:"90%", height:"80%", iframe:true});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#output").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择入库单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/OutputDFProductTpl')?>&ids=" + ids;
	});
	$("#output_df").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择入库单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/OutputDFInstoreTpl')?>&ids=" + ids;
	});
	$(".audit_arrived").click(function(){
		var ids = get_check();
		if (!confirm("确定已到仓？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/ConfirmPurchaseToArrive', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids;
	});
	$(".back_btn").click(function(){
		var ids = get_check();
		if (! confirm("确定返回已采购？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/ReturnPurchased', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids;
	});
	$(".audit_send").click(function(){
		var ids = get_check();
		if (!confirm("确定发送？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/ConfirmArriveToSend')?>&ids=" + ids;
	});
	$(".audit_storage").click(function(){
		var ids = get_check();
		if (!confirm("确定审核入库？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Storage::DFOverseas/AuditStorage', array(Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>&ids=" + ids;
	});
	$("#print_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.open("<?=url('Storage::DFOverseas/PrintPurchaseReceivingTable')?>&ids=" + ids);
	});
	$("#print_product_barcode_btn").click(function(){
		var ids = get_check();
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.open("<?=url('Storage::DFOverseas/PrintPurchaseProductBarcode')?>&ids=" + ids);
	});
	$(".edit_budget").click(function(){
		if ($(this).attr('type') == "button")
		{
			var ids = get_check();
			if ( ! ids)
			{
				alert("请选择订单！");
				return false;
			}
			$("#update_budget_id").val(ids);
			$("#budget_storage_time").val("");
		}
		else
		{
			$("#update_budget_id").val($(this).attr('id'));
			$("#budget_storage_time").val($(this).parent().prev().prev().prev().prev().prev().text());
		}
		$("#dialog_update_budget_time").dialog("open");
	});
	$(".send_create").click(function(){
		var ids = get_check();
		if ( ! ids)
		{
			alert("请选择订单！");
			return false;
		}
		window.location.href = '<?=url('Storage::Overseas/SendCreate')?>&ids=' + ids;
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>采购日期</th>
	<td>
		<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time'])?$_GET['begin_purchase_time']:''?>" /> to
		<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time'])?$_GET['end_purchase_time']:''?>" />
	</td>
</tr>
<tr>
	<th>采购单号</th>
	<td><input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number']) ? $_GET['purchase_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : ''?>" /></td>
</tr>
<tr>
	<th>采购人员</th>
	<td>
		<select name="purchase_user_id">
			<option value="">请选择..</option>
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if (isset($_GET['purchase_user_id'])&&$_GET['purchase_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>结款类型</th>
	<td>
		<select name="purchase_order_payment_type">
			<option value="">请选择..</option>
			<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
			<option value="<?=$pt['value']?>" <?if (isset($_GET['purchase_order_payment_type']) && $_GET['purchase_order_payment_type'] == $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
			<? endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id']) echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>状态</th>
	<td>
		<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/purchased/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/purchased/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/purchased/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/purchased/name')?></label>
		<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/arrived/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/arrived/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/arrived/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/arrived/name')?></label>
		<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/send/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/send/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/send/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/send/name')?></label>
		<label><input type="checkbox" name="purchase_order_status[<?=Q::ini('custom_flag/purchase_order_status/storaged/value')?>]" value="<?=Q::ini('custom_flag/purchase_order_status/storaged/value')?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists(Q::ini('custom_flag/purchase_order_status/storaged/value'), $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=Q::ini('custom_flag/purchase_order_status/storaged/name')?></label>
	</td>
</tr>
<tr>
	<th></th>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table class="list_table" width="100%" id="list">	
	<tr>
		<th width="20"></th>
		<th width="80">采购单号</th>
		<th width="80">仓库</th>
		<th width="80">结款类型</th>
		<th width="80">采购日期</th>
		<th width="80">完成日期</th>
		<th width="80">到仓日期</th>
		<th width="80">发送日期</th>
		<th width="80">预计入库日期</th>
		<th width="80">入库日期</th>
		<th width="60">实际总价</th>
		<th width="50">采购人</th>
		<th width="50">状态</th>
		<th>操作</th>
	</tr>
<?foreach ($purchase_order as $p):?>
<tr>
	<td><input type="checkbox" value="<?=$p['id']?>" /></td>
	<td><a class="detail" href="<?=url('Storage::DFoverseas/Detail', array('id'=>$p['id'], 'show_all' => 0))?>" ><?=$p['number']?></a></td>
	<td><?=$p['warehouse_name']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type', 'value', $p['payment_type'], 'name')?></td>
	<td title="采购时间：<?=$p['purchase_time'] . ' ' . $p['purchase_user_name']?>"><?=substr($p['purchase_time'], 0, 10)?></td>
	<td title="完成时间：<?=$p['complete_time'] . ' ' . $p['complete_user_name']?>"><?=substr($p['complete_time'], 0, 10)?></td>
	<td title="到仓时间：<?=$p['arrive_time'] . ' ' . $p['arrive_user_name']?>"><?=substr($p['arrive_time'], 0, 10)?></td>
	<td title="发送时间：<?=$p['send_time'] . ' ' . $p['send_user_name']?>"><?=substr($p['send_time'], 0, 10)?></td>
	<td title="预计入库时间：<?=$p['budget_storage_time']?>"><?=substr($p['budget_storage_time'], 0, 10)?></td>
	<td title="入库时间：<?=$p['storage_audit_time'] . ' ' . $p['storage_user_name']?>"><?=substr($p['storage_audit_time'], 0, 10)?></td>
	<td><?=sprintf('%.2f', $p['actual_amount'])?></td>
	<td><?=$p['purchase_user_name']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('purchase_order_status', 'value', $p['status'], 'name')?></td>
	<td>
		<?if ($p['status'] == Q::ini('custom_flag/purchase_order_status/purchased/value')): ?>
		<a onclick="if(!confirm('确定已到仓？')) return false;" href="<?=url('Storage::DFOverseas/ConfirmPurchaseToArrive', array('ids'=>$p['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">确认到仓</a>
		<?elseif ($p['status'] == Q::ini('custom_flag/purchase_order_status/arrived/value')): ?>
		<a onclick="if(!confirm('确定已发送？')) return false;" href="<?=url('Storage::DFOverseas/ConfirmArriveToSend', array('ids'=>$p['id']))?>">确认发送</a>
		<a onclick="if(!confirm('确定返回已采购？')) return false;" href="<?=url('Storage::DFOverseas/ReturnPurchased', array('ids'=>$o['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">返回已采购</a>
		<?elseif ($p['status'] == Q::ini('custom_flag/purchase_order_status/send/value')): ?>
		<a onclick="if(!confirm('确定审核入库？')) return false;" href="<?=url('Storage::DFOverseas/AuditStorage', array('ids'=>$p['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>">审核入库</a>
		<a class="edit_budget" id='<?=$p['id']?>'>修改预计入库</a>
		<?endif;?>
		<a target="_blank" href="<?=url('Storage::DFOverseas/PrintPurchaseReceivingTable', array('ids'=>$p['id']))?>">打印收货单</a>
		<a target="_blank" href="<?=url('Storage::DFOverseas/PrintPurchaseProductBarcode', array('ids'=>$p['id']))?>">打印条形码</a>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page;?>
<table class="list_table">
<tr>
	<td rowspan="4"><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td align="left">按勾选操作：
	<input type="button" value="确认到仓" class="button audit_arrived"/> | 
	<input type="button" value="确认发送" class="button audit_send" /> | 
	<input type="button" value="审核入库" class="button audit_storage"  /> | 
	<input type="button" value="修改预计入库" class="button edit_budget" style="width:110px" /> | 
	<input type="button" value="生成发送单" class="button send_create"  /> |
	<input type="button" value="返回已采购" class="button back_btn" />
	</td>
</tr>
<tr>
	<td align="left">按勾选打印：
	<input type="button" value="采购收货单" class="button" id="print_btn" /> | 
	<input type="button" value="产品条形码" class="button" id="print_product_barcode_btn" />
	</td>
</tr>
<tr>
	<td align="left">按勾选导出达方模板：
	<input type="button" class="button" id="output" value="产品资料" /> | 
	<input type="button" class="button" id="output_df" value="快速装箱" />
	</td>
</tr>
</table>
<div id="dialog_update_budget_time" title="批量修改预计入库日期">
<form method="post" action="<?=url('Storage::DFOverseas/UpdateBudgetStorageTime')?>">
	<input type="hidden" name="id" id="update_budget_id" value="" />
	<table class="form_table">
		<tr>
			<td>预计入库</td>
			<td><input type="text" id="budget_storage_time" name="budget_storage_time" class="datepicker" value="<?=isset($_GET['budget_storage_time'])?$_GET['budget_storage_time']:''?>" style="width:227px"/></td>
			<td><input type="submit" class="button" value="确认更改" /></td>
		</tr>
	</table>
</form>
</div>
<?php $this->_endblock();?>